package com.hhb.juc.redpack;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Red {

    private static double COUNT = 0;

    public static void main(String[] args) {
        /*for (int i = 0; i < 100; i++) {
            DecimalFormat format = new DecimalFormat("0.00");
            System.out.println(format.format(Math.random() * 10.12));
        }*/
        Busy busy = new Busy();
        busy.going(10,10);


    }
}


class Busy{

    public void going(int nums,double price){
        DecimalFormat format = new DecimalFormat("0.00");


        for (int i = 0; i < nums; i++) {
            String s = format.format(Math.random() * price);
            double parseDouble = Double.parseDouble(s);

            while (price-parseDouble>=(nums-1)*0.01){
                break;
            }


            if (price>0){
                price=price-parseDouble;
                System.out.println("第"+(i+1)+"抢到了 " + parseDouble + "元");
            }else {
                System.out.println("抢光了！");
                return;
            }

        }


    }

}
